<template>
  <div class="table-box">
    <div class="table">
      <div class="title">
        用户操作日志
      </div>
      <el-table :data="tableData" border style="width: 100%" stripe  height="76vh" max-height="76vh">
        <el-table-column type="index" width="50" align="center"/>
        <el-table-column prop="file_name" label="文件名" align="center"/>
        <el-table-column prop="handler" label="操作人" align="center"/>
        <el-table-column prop="handle_type" label="操作类型" align="center"/>
        <el-table-column prop="created_at" label="操作时间" align="center">
          <template #default = "{row}">
            {{computeDate(row.created_at)}}
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup>
import {ElMessage, ElTable, ElTableColumn} from "element-plus"
import {onMounted, ref} from "vue"
import {getLog} from "@/api/index.js"
import {useRouter} from "vue-router"

const router = useRouter()
const tableData = ref([])

onMounted(()=>{
  getlogs()
})

const getlogs = async () => {
  try {
    const user = JSON.parse(localStorage.getItem('syhyDocManSys'))
    const {data:res} = await getLog({
      userRoot:user.root
    })

    if(res.code === 501) {
      router.push('/login')
      return ElMessage({
        message:'身份已过期，请重新登陆',
        type:'warning'
      })
    } else if (res.code === 400) {
      return ElMessage({
        message:'您没有管理员权限，无法查看',
        type:'warning'
      })
    } else if (res.code === 401) {
      return ElMessage({
        message:'加载失败，请刷新重试',
        type:'warning'
      })
    } else {
      tableData.value = res.data
    }
  } catch (e) {
    console.log(e)
  }
}

const computeDate = (str) => {
  return str.slice(0,10)
}
</script>

<style scoped lang="less">
.table-box{
  height: 100vh;
  width: 100vw;
  box-sizing: border-box;
  padding-top: 3vh;
  padding-left: 7%;
  .table{
    width: 90%;
    height: 90%;
    .el-table{
      border-radius: 15px !important;
      box-shadow: 0 0 5px 5px lightgray;
      padding: 10px;
      box-sizing: border-box;
      .el-table--border .el-table__inner-wrapper {
        margin-bottom: 10px;
      }
    }
    .title{
      height: 9vh;
      letter-spacing: 1px;
      text-align: left;
      padding-left: 1vw;
      font-size: 2.8vh;
      line-height: 9vh;
    }
  }
}
:deep(.el-table tr ){
  height: 4vh;
  font-size: 1.5vh;
}
</style>